/*  extMDB 1.1 - an extension to gvSIG Desktop GIS to read GeoMedia MDB warehouses
 *  Copyright (C) 2008-2009  Stefano Orlando
 *  
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
/*
 * Revision 1.1  02/05/09 Stefano Orlando
 * Revision 1.0  06/02/09 Stefano Orlando
 */
package com.iver.cit.gvsig.mdb.panels;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
//import javax.swing.SwingWorker;
import org.jdesktop.swingworker.SwingWorker;

import org.cresques.cts.IProjection;

import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
import com.hardcode.gdbms.engine.values.Value;
import com.hardcode.gdbms.engine.values.ValueFactory;

import com.iver.andami.PluginServices;
import com.iver.andami.ui.mdiManager.IWindow;
import com.iver.andami.ui.mdiManager.WindowInfo;

import com.iver.cit.gvsig.ProjectExtension;
import com.iver.cit.gvsig.fmap.core.FShape;
import com.iver.cit.gvsig.fmap.core.IGeometry;
import com.iver.cit.gvsig.fmap.drivers.ConcreteMemoryDriver;
import com.iver.cit.gvsig.fmap.edition.EditableAdapter;
import com.iver.cit.gvsig.fmap.layers.FLayer;
import com.iver.cit.gvsig.fmap.layers.FLayers;
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;

import com.iver.cit.gvsig.mdb.core.MDBException;
import com.iver.cit.gvsig.mdb.core.MDBConversionException;
import com.iver.cit.gvsig.mdb.core.MDBWarehouse;
import com.iver.cit.gvsig.project.ProjectFactory;
import com.iver.cit.gvsig.project.documents.table.ProjectTable;
import com.iver.cit.gvsig.project.documents.table.ProjectTableFactory;
/**
 * Window that shows the progress of the conversion of a GeoMedia Warehouse
 * (and obviously executes the conversion's task).
 * @author Stefano Orlando
 */
public class MDBProgress extends JPanel implements IWindow {
	private static final long serialVersionUID = 1029060167453699090L;
	private javax.swing.JPanel mainPanel;
	private javax.swing.JPanel jPanel0;
	private javax.swing.JPanel jPanel1;
	private javax.swing.JPanel jPanel2;
	private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JProgressBar jProgressBar2;
    private static final int WINDOW_WIDTH = 310;
    private static final int WINDOW_HEIGHT = 107;
    
    private MDBWarehouse mdbWarehouse;
    private ArrayList<String> featureClasses;
    private ArrayList<IProjection> featureClassesProjs;
    private FLayers fls;
    private WindowInfo m_viewInfo;
    private MDBReaderTask mdbReaderTask;
    /**
     * Background task that executes the conversion.
     * @author Stefano Orlando
     */
    // Class SwingWorker<T,V>
    // T - the result type returned by this SwingWorker's doInBackground and get methods
    // V - the type used for carrying out intermediate results by this SwingWorker's publish and process methods
	private class MDBReaderTask extends SwingWorker<FLayers, Void>
	{
		private volatile String label2Text = "";
		private volatile String label3Text = "";
		private volatile String label4Text = "";
		private volatile String windowTitle = "";
		private volatile String button1Text = "";
		private volatile int progressBar1Progress = 0;
		FLayers fls;
		
		public void setLabel2Text(String label2Text) {
			if (this.label2Text.equalsIgnoreCase(label2Text)) return;
			String oldLabel2Text = this.label2Text;
			this.label2Text = label2Text;
		    if (getPropertyChangeSupport().hasListeners("label2Text")) {
		        firePropertyChange("label2Text", oldLabel2Text, this.label2Text);
		    }
		}
		public String getLabel2Text() {
			return label2Text;
		}
		public void setLabel3Text(String label3Text) {
			if (this.label3Text.equalsIgnoreCase(label3Text)) return;
			String oldLabel3Text = this.label3Text;
			this.label3Text = label3Text;
		    if (getPropertyChangeSupport().hasListeners("label3Text")) {
		        firePropertyChange("label3Text", oldLabel3Text, this.label3Text);
		    }
		}
		public String getLabel3Text() {
			return label3Text;
		}		
		public void setLabel4Text(String label4Text) {
			if (this.label4Text.equalsIgnoreCase(label4Text)) return;
			String oldLabel4Text = this.label4Text;
			this.label4Text = label4Text;
		    if (getPropertyChangeSupport().hasListeners("label4Text")) {
		        firePropertyChange("label4Text", oldLabel4Text, this.label4Text);
		    }
		}
		public String getLabel4Text() {
			return label4Text;
		}
		public void setProgressBar1Progress(int progressBar1Progress) {
			if (this.progressBar1Progress == progressBar1Progress) return;
			int oldProgressBar1Progress = this.progressBar1Progress;
			this.progressBar1Progress = progressBar1Progress;
			if (getPropertyChangeSupport().hasListeners("progressBar1Progress")) {
		        firePropertyChange("progressBar1Progress", oldProgressBar1Progress, this.progressBar1Progress);
		    }
		}
		public void setWindowTitle(String windowTitle) {
			if (this.windowTitle.equalsIgnoreCase(windowTitle)) return;
			String oldWindowTitle = this.windowTitle;
			this.windowTitle = windowTitle;
		    if (getPropertyChangeSupport().hasListeners("windowTitle")) {
		        firePropertyChange("windowTitle", oldWindowTitle, this.windowTitle);
		    }			
		}
		public String getWindowTitle() {
			return windowTitle;
		}
		public void setButton1Text(String button1Text) {
			if (this.button1Text.equalsIgnoreCase(button1Text)) return;
			String oldButton1Text = this.button1Text;
			this.button1Text = button1Text;
		    if (getPropertyChangeSupport().hasListeners("button1Text")) {
		        firePropertyChange("button1Text", oldButton1Text, this.button1Text);
		    }			
		}
		public String getButton1Text() {
			return button1Text;
		}
		protected FLayers doInBackground() throws Exception {
			int index = 0;
			boolean isError = false;
			boolean toSkip = false;
			Iterator<IProjection> iterFCP = featureClassesProjs.iterator();
			Iterator<String> iterFC = featureClasses.iterator();
	        while(iterFC.hasNext()) {
				String featureClassName = iterFC.next();
	        	setProgress(0);
	        	setLabel2Text(cutText(jLabel2, (PluginServices.getText(this,"feature_class") + " [" +
	        			++index + "/" + featureClasses.size() + "]: " + featureClassName), WINDOW_WIDTH));
	        	setLabel3Text(PluginServices.getText(this,"reading_database"));
	        	setLabel4Text(PluginServices.getText(this,"converting_data"));
	        	try {
					mdbWarehouse.setCurrentFeatureClass(featureClassName);
				} catch (MDBException ex) {
					setProgress(100);
					JOptionPane.showMessageDialog(
						null,
						ex.getMessage() +
							"\n" + PluginServices.getText(this,"feature_class_not_imported") +
							"\n" + PluginServices.getText(this,"feature_class") + ": " + featureClassName +
							"\n" + PluginServices.getText(this,"data_source_attached_error"),
						PluginServices.getText(this,"error_message"),
						JOptionPane.ERROR_MESSAGE);
					// skips the rest of the processing routine
					continue;
				}
	       		ConcreteMemoryDriver driver = null;
	       		driver = new ConcreteMemoryDriver();
	       		// retrieves the geometry type of the current feature class
        		int featureClassType = mdbWarehouse.getCurrentFeatureClassGeometryType();
	        	if (featureClassType == 1) driver.setShapeType(FShape.LINE);
	        	else if (featureClassType == 2) driver.setShapeType(FShape.POLYGON);
	       		else if (featureClassType == 3) driver.setShapeType(FShape.MULTI);
	       		else if (featureClassType == 10) driver.setShapeType(FShape.POINT);
	       		else if (featureClassType == -1) driver.setShapeType(FShape.NULL);
	       		// other geometries are not currently supported
	       		else {
	       			setProgress(100);
	       			JOptionPane.showMessageDialog(
						null,
						PluginServices.getText(this,"feature_class_unsupported_error") +
							"\n" + PluginServices.getText(this,"feature_class_not_imported") +
							"\n" + PluginServices.getText(this,"feature_class") + ": " + featureClassName + ".",
						PluginServices.getText(this,"error_message"),
						JOptionPane.ERROR_MESSAGE);
	       			driver = null;
	       			continue;
	       		}
	        	// retrieves the column's name of the current feature class
        		driver.getTableModel().setColumnIdentifiers(mdbWarehouse.getCurrentFeatureClassColNames());
	        	int auxRowColCount = mdbWarehouse.getCurrentFeatureClassColNames().length;
	        	int[] auxRowColTypes = mdbWarehouse.getCurrentFeatureClassColSQLTypes();
	        	Value[] auxRow = new Value[auxRowColCount];
	       		int numRecords = mdbWarehouse.getCurrentFeatureClassGeometryCount();
	       		if (numRecords > 0) setProgressBar1Progress(100);
	       		setLabel3Text(PluginServices.getText(this,"reading_database")+ " " + PluginServices.getText(this,"done_message"));
	        	int progress = 0;
	       		for (int j = 0; j < numRecords; j++) {
	       			if (isCancelled()) return null;
	       			if (progress != 100*(j+1)/numRecords) {
	       				progress = 100*(j+1)/numRecords;
	       				setProgress(progress);
	       			}
        			Object[] currRow = mdbWarehouse.getCurrentFeatureClassAttributes(j);
	        		for (int k = 0; k < auxRowColCount; k++) {
	        			Object obj = currRow[k];
	       				if (obj == null) auxRow[k] = ValueFactory.createNullValue();
	       				else {
	       					try {
	       						int type = auxRowColTypes[k];
	       						// GeoMedia's 'byte' type is unsigned while in Java is always signed,
	       						// so we use an 'integer' to represent a 'byte'
	       						if (type == java.sql.Types.TINYINT) type = java.sql.Types.INTEGER;
	       						auxRow[k] = ValueFactory.createValueByType(obj.toString(), type);
	       					} catch (java.text.ParseException ex) {
	       						System.err.println(PluginServices.getText(this,"data_table_error") +
	       								" (" + PluginServices.getText(this,"index") + ": " + j + "). " +
	       								PluginServices.getText(this,"feature_class") + ": " + featureClassName + ".");
	       						isError = true;
	       						// skips this feature
	       						toSkip = true;
	       						continue;
	       					}
	       				}
	        		}
	        		if (toSkip == true) {toSkip = false; continue;}
	        		IGeometry geom = null;
	        		try {
	        			geom = com.iver.cit.gvsig.mdb.core.MDBUtils.jts3D_to_IGeometry3D(mdbWarehouse.getCurrentFeatureClassGeometry(j));
	        		}
	        		catch (MDBException ex) {
	        			System.err.println(ex.getMessage() + " (" + PluginServices.getText(this,"index") + ": " + j + "). "
		        			+ PluginServices.getText(this,"feature_class") + ": " + featureClassName + ".");
		 				isError = true;
	        			// skips this geometry
		 				continue;
	        		}
	        		catch (MDBConversionException ex) {
	        			System.err.println(ex.getMessage() + " (" + PluginServices.getText(this,"index") + ": " + j + "). "
	        				+ PluginServices.getText(this,"feature_class") + ": " + featureClassName + ".");
	        			isError = true;
	        			// skips this geometry
	 					continue;
	 				}
	       			driver.addGeometry(geom, auxRow);
	       		}
	       		setLabel4Text(PluginServices.getText(this,"converting_data")+ " " + PluginServices.getText(this,"done_message"));
	       		IProjection featureClassProj = iterFCP.next();
	       		FLayer lyr = LayerFactory.createLayer(featureClassName, driver, featureClassProj);
	       		if(driver.getShapeType() == FShape.NULL) {
					ProjectExtension ext = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class);
					EditableAdapter ea = new EditableAdapter();
	       			SelectableDataSource sds = null;
					try {
						sds = ((FLyrVect)lyr).getRecordset();
						ea.setOriginalDataSource(sds);
						ProjectTable projectTable = ProjectFactory.createTable(lyr.getName(), ea);
						projectTable.setProjectDocumentFactory(new ProjectTableFactory());
						ext.getProject().addDocument(projectTable);
					} catch (ReadDriverException ex) {
						System.err.println(PluginServices.getText(this,"data_table_unexpected_error") +
	       					". " + PluginServices.getText(this,"feature_class") + ": " + featureClassName + ".");
	       				isError = true;
	       			}
	       		}	       		
	       		else fls.addLayer(lyr);
	       		setProgress(100);
	        }
	        jButton1.setName("OK");
	        setButton1Text(PluginServices.getText(this,"ok_button"));
	        setLabel3Text(PluginServices.getText(this,"reading_database")+ " " + PluginServices.getText(this,"done_message"));
	        setLabel4Text(PluginServices.getText(this,"converting_data")+ " " + PluginServices.getText(this,"done_message"));
	        setWindowTitle(PluginServices.getText(this,"importing_completed"));	        
	        if (isError == true) {
				JOptionPane.showMessageDialog(
	 				null,
	 				PluginServices.getText(this,"conversion_error"),
					PluginServices.getText(this,"error_message"),
 					JOptionPane.ERROR_MESSAGE);
	        }
	        return fls;
		}
		protected void done() {
			try {
				fls = get();
			} 
			catch (CancellationException ex) {
				fls = null;
			}
			catch (InterruptedException ex) {
				fls = null;
				ex.printStackTrace();
			}
			catch (ExecutionException ex) {
				JOptionPane.showMessageDialog(
		 			null,
		 			PluginServices.getText(this,"unexpected_execution_error"),
					PluginServices.getText(this,"error_message"),
	 				JOptionPane.ERROR_MESSAGE);
				fls = null;
				ex.printStackTrace();
			}
		}
		protected void set(FLayers fls) {
			this.fls = fls;
		}
		protected FLayers getResult() {
			return fls;
		}
	}
    /**
     * Cuts a string (appending '...') if the text length exceeds a given width in
     * pixels, using the font of a specified label.
     * @param label - the label which defines the font of the string
     * @param text - the text eventually to truncate
     * @param width - the reference width in pixels to compare to
     * @return the eventually truncated string
     * @author Stefano Orlando
     */
	private String cutText(javax.swing.JLabel label, String text, int width) {
		FontMetrics fontMetrics = label.getFontMetrics(label.getFont());
		if ((int) fontMetrics.getStringBounds(text, null).getWidth() > width) {
			for (int j = text.length()-1; j > 0; j--) {
				String test = text.substring(0, j) + "...";
				if ((int) fontMetrics.getStringBounds(test, null).getWidth() < width)
					return test;
			}
		}
		return text;
	}
    /**
     * Creates a new MDBProgress dialog that performs the conversion of a GeoMedia
     * Warehouse.
     * @param warehouse - the GeoMedia Warehouse to convert
     * @param featureClasses - the names of the Feature Classes to convert
     * @param featureClassesProjs - the Coordinate Systems to assign to the converted Feature Classes
     * @param fls - the result of the conversion as a collection of layers 
     * @author Stefano Orlando
     */	
	public MDBProgress(MDBWarehouse warehouse,
			ArrayList<String> featureClasses,
			ArrayList<IProjection> featureClassesProjs,
			FLayers fls) {
		super();
		this.mdbWarehouse = warehouse;
		this.featureClasses = featureClasses;
		this.featureClassesProjs = featureClassesProjs;
		this.fls = fls;
		initComponents();
		initActionListeners();
		makeLayout();
	}
    /**
     * Defines the layout of the window.
     * @author Stefano Orlando
     */
	private void makeLayout() {
		mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.PAGE_AXIS));
		jLabel1.setAlignmentX(Component.LEFT_ALIGNMENT);
		mainPanel.add(jLabel1);
		mainPanel.add(Box.createRigidArea(new Dimension(0, 5)));
		jLabel2.setAlignmentX(Component.LEFT_ALIGNMENT);
		mainPanel.add(jLabel2);
		mainPanel.add(Box.createRigidArea(new Dimension(0, 5)));
		jSeparator1.setAlignmentX(Component.LEFT_ALIGNMENT);
		mainPanel.add(jSeparator1);
		mainPanel.add(Box.createRigidArea(new Dimension(0, 5)));
		jPanel0.setLayout(new BoxLayout(jPanel0, BoxLayout.LINE_AXIS));
		jPanel0.add(jLabel3);
		jPanel0.add(Box.createHorizontalGlue());
		jPanel0.add(jProgressBar1);
		jPanel0.setAlignmentX(Component.LEFT_ALIGNMENT);
		mainPanel.add(jPanel0);
		mainPanel.add(Box.createRigidArea(new Dimension(0, 5)));
		jPanel1.setLayout(new BoxLayout(jPanel1, BoxLayout.LINE_AXIS));
		jPanel1.add(jLabel4);
		jPanel1.add(Box.createHorizontalGlue());
		jPanel1.add(jProgressBar2);
		jPanel1.setAlignmentX(Component.LEFT_ALIGNMENT);
		mainPanel.add(jPanel1);
		mainPanel.add(Box.createVerticalGlue());
		jPanel2.setAlignmentX(Component.LEFT_ALIGNMENT);
		jPanel2.add(jButton1);
		mainPanel.add(jPanel2);
		add(mainPanel);
		GridBagLayout gbl = new GridBagLayout();
		setLayout(gbl);
		GridBagConstraints c = new GridBagConstraints();
		c.insets = new Insets(5,5,5,5);
		c.fill = GridBagConstraints.BOTH;
        add(mainPanel, c);
        // forces the layout of components before calling getLayoutWeights()
        // otherwise the result of getLayoutWeights() is not valid
        gbl.layoutContainer(this);
        // sets weights of all columns and rows to 1
        double[][] weights = gbl.getLayoutWeights();
        for (int i=0; i<2; i++) {
            for (int j=0; j<weights[i].length; j++) {
                weights[i][j] = 1.0d;
            }
        }
        gbl.columnWeights = weights[0];
        gbl.rowWeights = weights[1];
	}
    /**
     * Initializes the GUI's components of the window.
     * @author Stefano Orlando
     */
    private void initComponents() {
		mainPanel = new javax.swing.JPanel();
		jPanel0 = new javax.swing.JPanel();
		jPanel1 = new javax.swing.JPanel();
		jPanel2 = new javax.swing.JPanel();
		jProgressBar1 = new javax.swing.JProgressBar();
		jProgressBar2 = new javax.swing.JProgressBar();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jButton1 = new javax.swing.JButton();

        FontMetrics fontMetrics = jLabel3.getFontMetrics(jLabel3.getFont());
		int jLabel3Width = (int) fontMetrics.getStringBounds(PluginServices.getText(this,"reading_database")+ " " + PluginServices.getText(this,"done_message"), null).getWidth();
        fontMetrics = jLabel4.getFontMetrics(jLabel4.getFont());
		int jLabel4Width = (int) fontMetrics.getStringBounds(PluginServices.getText(this,"converting_data")+ " " + PluginServices.getText(this,"done_message"), null).getWidth();    		
        int widthInPixels = Math.max(jLabel3Width, jLabel4Width);
        jLabel1.setText(cutText(jLabel1, PluginServices.getText(this,"warehouse") + ": " +
        		mdbWarehouse.getName(), WINDOW_WIDTH));
        jLabel2.setText(cutText(jLabel1, PluginServices.getText(this,"feature_class") + ": " +
        		featureClasses.get(0).toString(), WINDOW_WIDTH));
		jLabel3.setText(PluginServices.getText(this,"reading_database"));
        jLabel4.setText(PluginServices.getText(this,"converting_data"));
        jLabel3.setMinimumSize(new Dimension(widthInPixels, jLabel3.getMinimumSize().height));
        jLabel3.setPreferredSize(new Dimension(widthInPixels, jLabel3.getPreferredSize().height));
        jLabel3.setMaximumSize(new Dimension(widthInPixels, jLabel3.getMaximumSize().height));
        jLabel4.setMinimumSize(new Dimension(widthInPixels, jLabel4.getMinimumSize().height));
        jLabel4.setPreferredSize(new Dimension(widthInPixels, jLabel4.getPreferredSize().height));
        jLabel4.setMaximumSize(new Dimension(widthInPixels, jLabel4.getMaximumSize().height));
        jProgressBar1.setMinimumSize(new Dimension(WINDOW_WIDTH-widthInPixels-25, jProgressBar1.getMinimumSize().height));
        jProgressBar1.setPreferredSize(new Dimension(WINDOW_WIDTH-widthInPixels-25, jProgressBar1.getPreferredSize().height));
        jProgressBar1.setMaximumSize(new Dimension(WINDOW_WIDTH-widthInPixels-25, jProgressBar1.getMaximumSize().height));
        jProgressBar2.setMinimumSize(new Dimension(WINDOW_WIDTH-widthInPixels-25, jProgressBar2.getMinimumSize().height));
        jProgressBar2.setPreferredSize(new Dimension(WINDOW_WIDTH-widthInPixels-25, jProgressBar2.getPreferredSize().height));
        jProgressBar2.setMaximumSize(new Dimension(WINDOW_WIDTH-widthInPixels-25, jProgressBar2.getMaximumSize().height));
        jProgressBar1.setIndeterminate(true);
        jButton1.setName("cancel");
        jButton1.setText(PluginServices.getText(this,"cancel_button"));
    }
	/**
	 * Adds the listener for the jButton.
	 * @author Stefano Orlando
	 */
	private void initActionListeners () {
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	jButton1ActionPerformed(evt);
        		}
    		}
        );		
	}
	/**
	 * Starts the processing of the selected Warehouse launching a new SwingWorker thread.
	 * @author Stefano Orlando
	 */
	public void start() {
		mdbReaderTask = new MDBReaderTask();
		mdbReaderTask.set(fls);
		mdbReaderTask.addPropertyChangeListener(
			new PropertyChangeListener() {
				public void propertyChange(PropertyChangeEvent evt) {
					if ("progress".equals(evt.getPropertyName())) {
						int value = (Integer)evt.getNewValue();
			            if (value == 0) {
			            	jProgressBar1.setIndeterminate(true);
			            	jProgressBar2.setValue(0);
			            }
			            else {
			            	jProgressBar1.setIndeterminate(false);
			            	jProgressBar1.setValue(100);
			            	jProgressBar2.setValue(value);
			            }
					}
					if ("label2Text".equals(evt.getPropertyName())) {
						jLabel2.setText((String)evt.getNewValue());
					}
					if ("label3Text".equals(evt.getPropertyName())) {
						jLabel3.setText((String)evt.getNewValue());
					}
					if ("label4Text".equals(evt.getPropertyName())) {
						jLabel4.setText((String)evt.getNewValue());
					}
					if ("progressBar1Progress".equals(evt.getPropertyName())) {
						jProgressBar1.setMaximum(((Integer)evt.getNewValue()).intValue());
					}
					if ("windowTitle".equals(evt.getPropertyName())) {
						m_viewInfo.setTitle((String)evt.getNewValue());
					}
					if ("button1Text".equals(evt.getPropertyName())) {
						jButton1.setText((String)evt.getNewValue());
					}
				}
			});
		mdbReaderTask.execute();
	}
	/**
	 * Retrieves the imported Feature Classes as the result of the SwingWorker
	 * thread that has processed the Warehouse.
	 * @return a tree of layers (FLayers) representing the imported Feature Classes
	 * @author Stefano Orlando
	 */
	public FLayers getResult() {
		FLayers fls = mdbReaderTask.getResult();
		mdbReaderTask = null;
		return fls;
	}
	/**
	 * Processes the action on the cancel/OK button (jButton1).
	 * @param e - event
	 * @author Stefano Orlando
	 */
	private void jButton1ActionPerformed(ActionEvent e) {
		if (jButton1.getName().equalsIgnoreCase("cancel"))
			// causes isCancelled() to return true in doInBackground
			mdbReaderTask.cancel(true);
		PluginServices.getMDIManager().closeWindow(this);
		return;
	}
	/**
	 * Retrieves the informations on the window.
	 * @author Stefano Orlando
	 */
	public WindowInfo getWindowInfo() {
		m_viewInfo = new WindowInfo(WindowInfo.MODALDIALOG);
		m_viewInfo.setWidth(WINDOW_WIDTH);
		m_viewInfo.setHeight(WINDOW_HEIGHT);
		m_viewInfo.setTitle(PluginServices.getText(this, "importing"));
		return m_viewInfo;
	}
	public Object getWindowProfile() {
		// TODO Auto-generated method stub
		return null;
	}
}
